<template>
    <div class="dash-board">
        <el-container>
            <el-header>
                <div class="header-top">
                    <span class="title">DashBoard</span>
                    <div class="button">
                        <el-button round class="hover-button" @click="TypeChange()">Type Change</el-button>
                        <!-- 添加设备——待完成 -->
                        <el-button round class="hover-button" :disabled="true">Add Devices</el-button>
                    </div>
                </div>
                <!-- 标签切换——待完成 -->
                <el-tabs v-model="activeName" @tab-click="HandleClick">
                    <el-tab-pane label="Living Room" name="first"></el-tab-pane>
                    <el-tab-pane label="Bed Room" name="second"></el-tab-pane>
                    <el-tab-pane label="Bath Room" name="third"></el-tab-pane>
                    <el-tab-pane label="Kitchen" name="fourth"></el-tab-pane>
                </el-tabs>
            </el-header>
            <el-main>
                <el-row :gutter="15" style="height: 100%;">
                    <el-col :span="16" style="height: 100%;" class="main-left">
                        <!-- 质量数据检测 -->
                        <el-row :gutter="20">
                            <el-col v-for="(item, index) in qualitySensorInfo" :key="index" :span="8">
                                <quality-sensor :type="index" :name="item.name" :url="item.url"></quality-sensor>
                            </el-col>
                        </el-row>
                        <!-- 图表展示 -->
                        <el-row style="flex-grow: 1;">
                            <chart-component :type="chartType" :name="chartData.name"
                                :url="chartData.url"></chart-component>
                        </el-row>
                    </el-col>
                    <!-- 设备控制 -->
                    <el-col :span="8" style="height: 100%;" class="main-right">
                        <el-row v-for="(item, index) in DeviceControlInfo" :key="index">
                            <device-control :type="index" :name="item.name" :url="item.url"></device-control>
                        </el-row>
                    </el-col>
                </el-row>
            </el-main>
            <el-footer class="footer-text">
                <span style="margin-right: 20px;">Copyright © 2024 - 2024 Iot Team</span>
                <span>Made By wwwangzd</span>
            </el-footer>
        </el-container>
    </div>
</template>

<script>
import QualitySensor from '@/components/QualitySensor.vue';
import DeviceControl from '@/components/DeviceControl.vue';
import ChartComponent from '@/components/ChartComponent.vue';
export default {
    name: 'DashBoard',
    components: { QualitySensor, DeviceControl, ChartComponent },
    data() {
        return {
            chartType: 0,
            activeName: 'first',
            qualitySensorInfo: [
                {
                    name: 'Air Quality',
                    url: `${this.$apiPrefix}/air/latest`
                },
                {
                    name: 'Indoor Temperature',
                    url: `${this.$apiPrefix}/temperature/latest`
                },
                {
                    name: 'Indoor Humidity',
                    url: `${this.$apiPrefix}/humidity/latest`
                },
            ],
            DeviceControlInfo: [
                {
                    name: 'HomeTV',
                    url: `${this.$apiPrefix}/device`
                },
                {
                    name: 'Lighting',
                    url: `${this.$apiPrefix}/device`
                },
                {
                    name: 'AirCondition',
                    url: `${this.$apiPrefix}/device`
                },
            ],
            chartComponentInfo: [
                {
                    name: 'Recent Air Quality(One Day)',
                    url: `${this.$apiPrefix}/air/recent`
                },
                {
                    name: 'Recent Temperature(One Day)',
                    url: `${this.$apiPrefix}/temperature/recent`
                }, {
                    name: 'Recent Humidity(One Day)',
                    url: `${this.$apiPrefix}/humidity/recent`
                }
            ]
        };
    },
    computed: {
        chartData() {
            return this.chartComponentInfo[this.chartType];
        },
    },
    methods: {
        HandleClick(tab) {
            this.activeName = tab.name;
            console.log(this.activeName);
        },
        TypeChange() {
            this.chartType = (this.chartType + 1) % 3;
            console.log(this.chartType);
        }
    }
};
</script>

<style scoped>
.dash-board {
    height: 100%;
}

.el-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    background-color: #F8FAFE;
}

.el-header {
    display: flex;
    flex-direction: column;
    height: 110px !important;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    padding: 0 10px;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 70px;
}

.title {
    font-size: 20px;
    font-weight: bold;
}

.button .el-button {
    color: white;
    font-size: 16px;
    font-weight: bold;
}

.button .el-button:nth-child(1) {
    background-color: #007AFF;
    margin-right: 20px;
}

.button .el-button:nth-child(2) {
    background-color: #7728F5;
}

.hover-button {
    position: relative;
    overflow: hidden;
    transition: color 0.4s;
}

.hover-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 300%;
    height: 300%;
    background: rgba(0, 0, 0, 0.1);
    transition: all 0.4s;
    transform: translate(-50%, -50%) scale(0);
    border-radius: 50%;
}

.hover-button:hover::before {
    transform: translate(-50%, -50%) scale(1);
}

.hover-button:hover {
    color: #988FA7;
    outline: none;
}

:deep(.el-tabs__header) {
    margin: 0;
}

/* 去掉长分割线 */
:deep(.el-tabs__nav-wrap::after) {
    display: none;
}

/* 去掉下划线 */
:deep(.el-tabs__active-bar) {
    background-color: #7728F5;
}

:deep(.el-tabs__item) {
    color: #9A9A9A;
    font-weight: bold;
    padding: 0px 25px;
}

:deep(.el-tabs__item.is-active) {
    color: #7728F5;
}

:deep(.el-tabs__item:hover) {
    color: #7728F5;
}

.el-main {
    padding: 10px;
}

.main-left,
.main-right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.el-footer {
    background-color: rgb(26, 24, 24);
    height: 30px !important;
    padding: 0 10px;
}

.footer-text {
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 11px;
    font-weight: bold;
}
</style>